package com.itouch.bracelet.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class MyImageAdapter extends BaseAdapter{

	private String[] mylist;
	private Context mContext;
	private DisplayImageOptions option;
	private int type;
	
	public MyImageAdapter(String[] list,Context c,int type) {
		// TODO Auto-generated constructor stub
		mylist=list;
		mContext=c;
		option=new DisplayImageOptions.Builder().cacheInMemory(true)
				.cacheOnDisc(true)
				.build();
		this.type=type;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mylist.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView iv;
		if(convertView==null){
			iv=new ImageView(mContext);
		}else{
			iv=(ImageView) convertView;
		}
		if(type==1){
			iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,  (int) (((Activity)mContext).getWindowManager().getDefaultDisplay().getWidth()/1.5)));
		}else if(type==2){
			iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,  (int) (((Activity)mContext).getWindowManager().getDefaultDisplay().getWidth()/2.5)));
		}else if(type==3){
			iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,  (int) (((Activity)mContext).getWindowManager().getDefaultDisplay().getWidth()/3.5)));
		}
		iv.setPadding(10, 10, 10, 10);
		iv.setScaleType(ScaleType.CENTER_CROP);
		ImageLoader.getInstance().displayImage(mylist[position], iv,option);
		return iv;
	}

	
	
}
